package org.cll.pattern.singleton.exampleone;


import org.cll.pattern.singleton.exampleone.OrderController;
import org.cll.pattern.singleton.exampleone.UserController;
import sun.rmi.runtime.Log;

import java.io.IOException;



/**
 * @ClassName TestSingletonOne
 * @Description TODO
 * @Author Administrator
 * @Date 2024-09-04 18:17:46
 * @Version 1.0
 **/
public class TestSingletonOne {
    public static void main(String[] args) throws IOException {
        UserController userController = new UserController();
        OrderController orderController = new OrderController();

        for (int i = 0; i < 4; i++) {

        }

        //写两个线程，分别调用userController.login();orderController.create()
        // 创建一个线程来执行 userController.login()
        Thread loginThread = new Thread(() -> {
                try {
                    userController.login("用户线程的消息",null);
                } catch (IOException | InterruptedException e) {
                    throw new RuntimeException(e);
                }
        });

        // 创建一个线程来执行 orderController.create()
        Thread createThread = new Thread(() -> {
                try {
                    orderController.create("订单线程的消息");
                } catch (IOException | InterruptedException e) {
                    throw new RuntimeException(e);
                }


        });

        // 启动两个线程
        loginThread.start();
        createThread.start();

        // 等待两个线程执行完毕
        try {
            loginThread.join();
            createThread.join();

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("结束!");
    }

}
